// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

#include <memory>

#include <cxxopts.hpp>
#include <spdlog/spdlog.h>

#include "appcoin2/support/feed/fastfeed_util.h"
#include "coin2/app/driver.h"
#include "coin2/base/config/app_config.h"


int main(int argc, char* argv[]) {
  DriverConfig app;

  cxxopts::Options opt("FastFeed Converter", "Generate FastFeed");
  SetupOptions(&opt);
  opt.add_options()(
      "out-dir",
      "fastfeed out directory",
      cxxopts::value<std::string>()->default_value(
          "/remote/iosg/coin-2/buckets/feed.derived.feed_cache.coin2"));
  opt.add_options()(
      "log-dir",
      "fastfeed log directory",
      cxxopts::value<std::string>()->default_value("/remote/iosg/jenkins-2/bot-coin/jenkins/workspace/coin2_fastfeed/logs"));
  opt.add_options()(
      "pi-dir",
      "product info directory",
      cxxopts::value<std::string>()->default_value(""));

  auto res = opt.parse(argc, argv);

  ParseOptionsIntoConfig(res, &app);

  spdlog::info("=== FastFeed Converter start ===");
  LogAppConfig(res, app);
  spdlog::warn("running ..");
  spdlog::warn("out-dir: {}", res["out-dir"].as<std::string>());

  FastFeedConverter converter(res["out-dir"].as<std::string>(),
                              res["multiplier"].as<int>(),
                              res["pi-dir"].as<std::string>());

  ConstantInjectionBuilder ci_builder = ConstantInjectionBuilder();
  ci_builder.arbitration_config_toml = "data/coin2/feed/archive_arbitration.toml";
  coin2::app::Driver driver(app, &converter, ci_builder);
  driver.Run();

  spdlog::info("=== FastFeed Converter done ===");
  return 0;
}
